import {InputNumber as AntdInputNumber, Form} from "antd";
import BaseEntity from "@/type/BaseEntity";
import InputProps from "@/common/form/porps";
import React from "react";
import type {Rule} from "rc-field-form/lib/interface";

interface IProps<T extends BaseEntity> extends InputProps<T>{
    /**
     * 前缀
     */
    before?: string | React.ReactNode
    /**
     * 后缀
     */
    after?: string | React.ReactNode
    /**
     * 最小值
     */
    min?: number
    /**
     * 最大值
     */
    max?: number
}

const InputNumber = <T extends BaseEntity>(props: IProps<T>) => {
    const rules: Rule[] = [
        {
        required: props.required,
        message: `请输入或选择${props.label}值!`
        },
    ];
    return (
        <Form.Item<T> name={props.name as any} label={props.label} required={props.required} rules={rules}>
            <AntdInputNumber
                style={{width: "100%"}}
                addonBefore={props.before}
                addonAfter={props.after}
                min={props.min}
                max={props.max}
            />
        </Form.Item>
    );
};

export default InputNumber;